/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Graficos;

import java.awt.Dimension;
import java.awt.ScrollPane;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Administrador
 */
public class graficoCanFel {

public void canFel(){

    ArrayList nomes = new ArrayList();
    ArrayList valores = new ArrayList();
    float total = 0;
    float temp = 0;

    DecimalFormat df = new DecimalFormat("#,###.00");


    Statement stm = null;
        String result = null;
        String consTot = "SELECT COUNT(ACOD) AS CONT FROM CPARC.CAD_ANIM WHERE AESP = 1 OR AESP = 2";
        String consAnim = "SELECT CASE WHEN AESP = 1 THEN 'Caninos' ELSE 'Felinos' END AS ESP,COUNT(ACOD) AS CONT FROM CPARC.CAD_ANIM WHERE AESP = 1 OR AESP = 2 GROUP BY AESP";
        

        try  {
        stm = (Statement) conexao.getConnection(true).createStatement();
        ResultSet rs = stm.executeQuery(consTot);

        rs.next();
        total = (float) rs.getDouble("CONT");

        rs = stm.executeQuery(consAnim);
        while(rs.next()){

            temp = (rs.getFloat("CONT")/total)*100;
            nomes.add(rs.getString("ESP") + " - " + df.format(temp));
            
            valores.add(temp);


        }

        }
        catch(SQLException e){
            String status = e.getMessage();
            System.out.println(status);
        }

        JPanel painel = new JPanel();
       JFrame frame = new JFrame();
        ScrollPane scroll = new ScrollPane(1);

        painel.add(graficoPizza.pizza3DStatic(nomes, valores,
               "Felinos X Caninos"));

        scroll.add(painel);
	frame.getContentPane().add(scroll);
	frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
	frame.setTitle("Caninos x Felinos");
	frame.setPreferredSize(new Dimension(750, 520));
	frame.pack();
	frame.setVisible(true);


        //System.out.println(total);
        //System.out.println(nomes);
        //System.out.println(valores);


}
}
